package com.example.mytest1;

import android.graphics.Color;
import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    private TextView titleTextView;
    private EditText usernameEditText;
    private EditText passwordEditText;
    private Button loginButton;
    private TextView resultTextView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        Log.d(TAG, "onCreate: Activity创建完成");  // 调试信息
        Log.i(TAG, "这是一个信息级别的日志");       // 一般信息
        Log.w(TAG, "这是一个警告级别的日志");       // 警告
        Log.e(TAG, "这是一个错误级别的日志");       // 错误

        try {
            // 一些可能出错的代码
        } catch (Exception e) {
            Log.e(TAG, "发生错误: ", e);  // 带异常堆栈的日志
        }
        // 初始化视图
        titleTextView = findViewById(R.id.titleTextView);
        usernameEditText = findViewById(R.id.usernameEditText);
        passwordEditText = findViewById(R.id.passwordEditText);
        loginButton = findViewById(R.id.loginButton);
        resultTextView = findViewById(R.id.resultTextView);

        // 设置按钮点击事件
        loginButton.setOnClickListener(v -> {
            String username = usernameEditText.getText().toString();
            String password = passwordEditText.getText().toString();

            if (username.isEmpty() || password.isEmpty()) {
                resultTextView.setText("用户名和密码不能为空");
                resultTextView.setTextColor(Color.RED);
            } else {
                resultTextView.setText("登录成功，欢迎 " + username);
                resultTextView.setTextColor(Color.GREEN);
            }

            resultTextView.setVisibility(View.VISIBLE);
        });

    }


}